from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
from WMS_unittest.tools_unit import Tools
from WMS_unittest.mydb import Mysql
import unittest
import logging
from ddt import ddt,file_data

@ddt
class Wms(unittest.TestCase):
    def setUp(self) -> None:
        self.db = Mysql('10.59.9.14', 'root', 'yidong666', 'a3mall')
        Tools().log1()
        self.driver = webdriver.Edge()
        self.driver.get('http://10.59.9.32/jeewms/loginController.do?login')
        self.driver.maximize_window()
        sleep(2)
    def tearDown(self) -> None:
        self.db.close()
        sleep(5)
        self.driver.quit()

    @file_data("data.yaml")
    def test_select_yh(self,name1,num,mail):
        try:
            logging.info("*****************************************")
            # 基础资料-客户
            # 1、强制等待
            sleep(5)
            # 输入验证码
            self.driver.find_element(By.ID, 'but_login').click()
            # 2、隐式等待
            self.driver.implicitly_wait(2)
            # 滚动50像素
            self.driver.execute_script('window.scrollTo(0,50)')
            # 点击基础资料
            # 2、显示等待
            WebDriverWait(self.driver,20,0.4).until(EC.presence_of_element_located((By.XPATH, '//*[@id="sidebar"]/ul/li[4]'))).click()
            sleep(2)
            # 点击客户
            self.driver.find_element(By.CSS_SELECTOR,
                                     '#sidebar > ul > li.hover.open > ul > li:nth-child(1) > a').click()
            sleep(2)
            # 进入frame框架
            f = self.driver.find_element(By.XPATH, '//*[@id="tab_8a7ba3345d93bb87015d93e67ba4001f"]/iframe')
            self.driver.switch_to.frame(f)
            sleep(2)
            # 输入名称：马云
            na = self.driver.find_element(By.NAME, 'zhongWenQch')
            na.send_keys(name1)
            # 1、鼠标事件：右击
            ActionChains(self.driver).context_click(na).perform()
            # 输入合同号：100011
            ht = self.driver.find_element(By.XPATH, '//input[@name="zhuJiMa" and @class="inuptxt"]')
            ht.send_keys(num)
            # 2、鼠标事件：双击
            ActionChains(self.driver).double_click(ht).perform()
            # 1、键盘事件：复制
            ht.send_keys(Keys.CONTROL, 'c')
            # 输入编码：001
            self.driver.find_element(By.XPATH,
                                     '/html/body/div/div[1]/div/div/div[2]/div[1]/div[1]/form/span[3]/input').send_keys(
                mail)
            # 点击查询
            self.driver.find_element(By.CSS_SELECTOR,
                                     '#mdCusListtb > div.datagrid-toolbar > span:nth-child(2) > a:nth-child(1) > span').click()
            sleep(2)
            address = self.driver.find_element(By.XPATH, '//*[@id="datagrid-row-r2-2-0"]/td[29]/div')
            # 3、鼠标事件：悬停
            ActionChains(self.driver).move_to_element(address).perform()
            sleep(3)
            # 断言地址：温泉路
            dy = address.text
            print('dy', dy)
            self.assertIn('温泉路', dy)
            sleep(5)
            # 2、键盘事件：粘贴
            na.send_keys(Keys.CONTROL, 'v')
            # 3、键盘事件：回车
            na.send_keys(Keys.ENTER)
            logging.info("*****************************************")

        except Exception as e:
            logging.info("*****************************************")
            # 断言地址：温泉路
            dy = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div/div[2]/div[2]/div[2]/div[1]/div/table/tbody/tr/td[29]/div').text
            self.assertNotIn('温泉路', dy)
            print('dy', dy)
            sleep(5)
            logging.info("*****************************************")
            print(e)

if __name__ == '__main__':
    unittest.main()
